﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JCTimes.DomainModel.Entity;
using JCTimes.DomainModel.Repository;

namespace JCTimes.EFRepository.RepositoryImpl
{
    public class FunctionsRepository : BaseRepository<Function>, IFunctionsRepository {
        public IEnumerable<Function> GetMenu(string userID, string roleID) {
            var query = from f in db.Functions
                        from fr in db.FunctionRoles
                        where f.ID == fr.FunctionID && f.IsDisplay == 1
                        where fr.UsersID == userID || fr.RoleID == roleID
                        select f;
            return query.Distinct().OrderBy(f => f.OrderID);
        }
       
        public IQueryable<Function> GetItems(Func<Function, bool> pred) {
            return db.Functions.Where(pred).AsQueryable();
        }

        public void AddFunctionRole(FunctionRole fr) {
            db.FunctionRoles.Add(fr);
        }
    }
}
